﻿/****** Object:  StoredProcedure [dbo].[USP_GXBZ_EMR_ZYBASY]    Script Date: 2018/12/11 18:45:42 ******/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_GXBZ_EMR_ZYBASY]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [dbo].[USP_GXBZ_EMR_ZYBASY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/**********
[版本号]1.0.0.0.0
[创建时间]2018-12-05
[作者]Z_DD
[版权]卫宁健康科技集团股份有限公司
[描述] 
[功能说明]重庆cdc数据上传--住院病案首页GXBZ_EMR_ZYBASY数据上传
[返回值]
[调用的USP]
[调用实例] EXEC USP_GXBZ_EMR_ZYBASY
[修改历史]

**********/
CREATE PROC [dbo].[USP_GXBZ_EMR_ZYBASY]    
AS 
  SET XACT_ABORT ON 
DECLARE
	@kssj datetime,					--上传开始时间
	@jssj datetime					--上传结束时间
BEGIN 


		IF NOT EXISTS(SELECT table_time FROM SYS_SJSC_TABLE 
		WHERE TABLE_NAME = 'GXBZ_EMR_ZYBASY')
		BEGIN 
			INSERT INTO SYS_SJSC_TABLE(TABLE_NAME,TABLE_TIME)
			VALUES('GXBZ_EMR_ZYBASY','2015-07-01')
		END 
		
		--获取已上传的时间
		SELECT @kssj =TABLE_TIME  FROM SYS_SJSC_TABLE(NOLOCK)
		WHERE TABLE_NAME = 'GXBZ_EMR_ZYBASY'
		
		--获取源表中最大上传时间
		SELECT @jssj = MAX(TBRQ) FROM ZY_BASY_PGBG(NOLOCK)
		
		IF(@jssj>ISNULL(@kssj,'1900-01-01'))
		BEGIN
			BEGIN TRY
			BEGIN TRAN
		-------创建临时表  
		CREATE TABLE #TEMP_GXBZ_EMR_ZYBASY(  
			ZYLSH varchar(64)  not null,
			XGBZ  varchar(1) not null,
			GRJBXXBSH varchar(64)  not null,
			CXJMJKDABH varchar(17)  not null,
			JKKH  varchar(64)  null,
			ZYHBS varchar(32)  null,
			BLH varchar(36)  null,
			BAH varchar(36)  null,
			XZZXMCMPH varchar(140) null,
			XZZCMC varchar(70)  null,
			XZZXMC varchar(70)  null,
			XZZQXMC  varchar(70)  null,
			XZZSMC varchar(70)  null,
			XZZSSMC  varchar(70)  null,
			XZZYB varchar(16)  null,
			XZZXXDZ  char(140) null,
			CSDQXMC  varchar(70)  null,
			CSDDSMC  varchar(70)  null,
			CSDSSMC  varchar(70)  null,
			CSDYB varchar(16)  null,
			CSDXXDZ  varchar(140) null,
			GZDWMC varchar(70)  null,
			GZDWDZDHHM varchar(70)  null,
			GZDWDZMPH varchar(140) null,
			GZDWDZCMC varchar(70)  null,
			GZDWDZXMC varchar(70)  null,
			GZDWDZQXMC varchar(70)  null,
			GZDWDZSMC varchar(70)  null,
			GZDWSSMC varchar(70)  null,
			GZDWDZYB varchar(70)  null,
			GZDWXXDZ varchar(140) null,
			HJDZDZMPH varchar(70)  null,
			HJDZDZCMC varchar(70)  null,
			HJDZDZXMC varchar(70)  null,
			HJDZQXMC varchar(70)  null,
			HJDZSMC  varchar(70)  null,
			HJDZSSMC varchar(70)  null,
			HJDZYB varchar(16)  null,
			HJDXXDZ  varchar(140) null,
			JGSMC varchar(70)  null,
			JGSSMC varchar(70)  null,
			ZYLBDM varchar(4) null,
			ZYLBMC varchar(20)  null,
			YLJGDM varchar(33)  null,
			YLJGMC varchar(70)  null,
			KFSSGH varchar(64)  null,
			KFYSXM varchar(30)  null,
			WDGLJGDM varchar(22)  null,
			WDGLJGMC varchar(70)  null,
			KZRGH varchar(64)  null,
			KZRXM varchar(30)  null,
			ZRYSBM varchar(64)  null,
			ZRYSXM varchar(30)  null,
			ZZYSBM varchar(64)  null,
			ZZYSXM varchar(30)  null,
			ZYYSBM varchar(64)  null,
			ZYYSXM varchar(30)  null,
			ZRHSBM varchar(64)  null,
			ZRHSXM varchar(30)  null,
			JXYSBM varchar(64)  null,
			JXYSXM varchar(30)  null,
			SXYSBM varchar(64)  null,
			SXYSXM varchar(30)  null,
			BMYBM varchar(64)  null,
			BMYXM varchar(30)  null,
			YLXRGX varchar(1) null,
			LXRDZMPH varchar(140) null,
			LXRDZCMC varchar(70)  null,
			LXRDZXMC varchar(70)  null,
			LXRDZQXMC varchar(70)  null,
			LXRDZSMC varchar(70)  null,
			LXRDZSSMC varchar(70)  null,
			LXRDZYB  varchar(16)  null,
			LXRXXDZ  varchar(140) null,
			LXRDZDHHM varchar(20)  null,
			LXRXM varchar(30)  null,
			RYTJ  varchar(4) null,
			RYSJ  datetime null,
			CYSJ  datetime null,
			BFHBS varchar(20)  null,
			RYKBBFMC varchar(100) null,
			RYKBDM varchar(64)  null,
			RYKBMC varchar(32)  null,
			XSERYTZ  varchar(64)  null,
			XSECSTZ  varchar(64)  null,
			JBZDMC varchar(100)  null,
			JBZDDM varchar(20) null,
			BLZDMC varchar(100) null,
			BLZDBM varchar(20)  null,
			JBZTDM varchar(20)  null,
			SSZDYY varchar(256) null,
			SSZDBM varchar(20)  null,
			RYQT  int null,
			RYQXS int null,
			RYQF  int null,
			RYHT  int null,
			RYHXS int null,
			RYHF  int null,
			ZKKBMC varchar(32)  null,
			ZKKBDM varchar(64)  null,
			CYZYQZRQ datetime null,
			CYZYZDMC varchar(100) null,
			CYZYJBZDDM varchar(20)  null,
			RYZYJBZDDM varchar(20)  null,
			CYQTQZRQ datetime null,
			CYQTZDMC varchar(100) null,
			CYQTJBZDDM varchar(20)  null,
			RYQTJBZDDM varchar(20)  null,
			LYFS  varchar(4) null,
			LYYYMC varchar(70)  null,
			GMYW  varchar(200) null,
			ABOXXDM  char(1)  null,
			RHXXDM varchar(1) null,
			SSDM  varchar(20)  null,
			SSRQ  datetime null,
			SSYSGH varchar(64)  null,
			SSYSXM varchar(30)  null,---
			SSYSZ1GH varchar(64)  null,
			SSYSZ1XM varchar(30)  null,
			SSYSZ2GH varchar(64)  null,
			SSYSZ2XM varchar(30)  null,
			SSCZMC varchar(128) null,
			SSJB  varchar(4) null,
			SSQKLBDM varchar(2) null,
			QKYHDJ varchar(4) null,
			MZYSGH varchar(64)  null,
			MZYSXM varchar(30)  null,
			ZYCS  int null,
			SJZYTS decimal(5) null,
			CYBFDM varchar(20)  null,
			CYKBBFMC varchar(100) null,
			CYKBDM varchar(64)  null,
			CYKBMC varchar(32)  null,
			ZKRQ  datetime null,
			ZKYSBM varchar(64)  null,
			ZKYSXM varchar(30)  null,
			ZKHSBM varchar(64)  null,
			ZKHSXM varchar(30)  null,
			CYZZYJHMD varchar(250) null,
			YLFKFSDM varchar(2) null,
			ZFY decimal(8,2) null,
			ZFJE  decimal(8,2) null,
			YLFWF decimal(8,2) null,
			ZLCZF decimal(8,2) null,
			HLF decimal(8,2) null,
			ZHYLQTFY decimal(8,2) null,
			BLZDF decimal(8,2) null,
			SYSZDF decimal(8,2) null,
			YXXZDF decimal(8,2) null,
			LCZDXMF  decimal(8,2) null,
			FSSZLXMF decimal(8,2) null,
			WLZLF decimal(8,2) null,
			SSZLF decimal(8,2) null,
			SSMZF decimal(8,2) null,
			SSF decimal(8,2) null,
			KFF decimal(8,2) null,
			ZYZLF decimal(8,2) null,
			XYF decimal(8,2) null,
			KJYWF decimal(8,2) null,
			ZCHYF decimal(8,2) null,
			ZCYF  decimal(8,2) null,
			XF  decimal(8,2) null,
			BDBLZPF  decimal(8,2) null,
			QDBLZPF  decimal(8,2) null,
			NXYZLZPF decimal(8,2) null,
			XBYZLZPF decimal(8,2) null,
			JCYYCLF  decimal(8,2) null,
			ZLYYCLF  decimal(8,2) null,
			SSYYCLF  decimal(8,2) null,
			QTF decimal(8,2) null,
			MJ  varchar(16)  not null,
			TBRQ  datetime not null,
			SCZT  varchar(1) not null,
			CS_JYBZ  int not null,
			SCSJ  datetime not null
		) ON [PRIMARY]
		
		--插业务数据到临时表
		INSERT INTO #TEMP_GXBZ_EMR_ZYBASY (ZYLSH,XGBZ,GRJBXXBSH,CXJMJKDABH,JKKH,ZYHBS,BLH,BAH,XZZXMCMPH,XZZCMC,XZZXMC,
			XZZQXMC,XZ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SDM,
			ZFY,ZFJE,YLFWF,ZLCZF,HLF,ZHYLQTFY,BLZDF,SYSZDF,YXXZDF,LCZDXMF,FSSZLXMF,WLZLF,SSZLF,SSMZF,
			SSF,KFF,ZYZLF,XYF,KJYWF,ZCHYF,ZCYF,XF,BDBLZPF,QDBLZPF,NXYZLZPF,XBYZLZPF,JCYYCLF,ZLYYCLF,
			SSYYCLF,QTF,MJ,TBRQ,SCZT,CS_JYBZ,SCSJ)
		SELECT
			A.JZLSH ZYLSH,
			A.XGBZ XGBZ,
			(select top 1 JBXX.GRJBXXBSH from GXBZ_DA_GR_JBXX JBXX where JBXX.zjhm = A.SFZH) AS GRJBXXBSH,
			(select top 1 JBXX.CXJMJKDABH from GXBZ_DA_GR_JBXX JBXX where JBXX.zjhm = A.SFZH) AS CXJMJKDABH,
			A.JKKH JKKH,
			B.CISID ZYHBS,
			NULL BLH,
			A.BAHM BAH,
			F.XZZXMCMPH XZZXMCMPH,
			F.XZZCMC XZZCMC,
			F.XZZXMC XZZXMC,
			F.XZZQXMC XZZQXMC,
			F.XZZSMC XZZSMC,
			F.XZZSSMC XZZSSMC,
			F.XZZYB XZZYB,
			F.XZZXXDZ XZZXXDZ,
			F.CSDQXMC CSDQXMC,
			F.CSDDSMC CSDDSMC,
			F.CSDSSMC CSDSSMC,
			NULL CSDYB,
			F.CSDXXDZ CSDXXDZ,
			F.GZDWMC GZDWMC,
			F.GZDWDZDHHM GZDWDZDHHM,
			F.GZDWDZMPH GZDWDZMPH,
			F.GZDWDZCMC GZDWDZCMC,
			F.GZDWDZXMC GZDWDZXMC,
			F.GZDWDZQXMC GZDWDZQXMC,
			F.GZDWDZSMC GZDWDZSMC,
			F.GZDWSSMC GZDWSSMC,
			F.GZDWDZYB GZDWDZYB,
			F.GZDWXXDZ GZDWXXDZ,
			F.HJDZDZMPH HJDZDZMPH,
			F.HJDZDZCMC HJDZDZCMC,
			F.HJDZDZXMC HJDZDZXMC,
			F.HJDZQXMC HJDZQXMC,
			F.HJDZSMC HJDZSMC,
			F.HJDZSSMC HJDZSSMC,
			F.HJDZYB HJDZYB,
			F.HJDXXDZ HJDXXDZ,
			F.JGSMC JGSMC,
			F.JGSSMC JGSSMC,
			F.ZYLBDM ZYLBDM,
			(SELECT top 1 XMMC FROM GBT2261_4_2003 WHERE XMDM=A.ZYDM) ZYLBMC,
			isnull(C.SPTDM,'500103000000001') YLJGDM,
			isnull(C.JGMC,'渝中区卫计委') YLJGMC,
			F.ZKYSBM KFSSGH,
			F.ZKYSXM KFYSXM,
			'500103000000001' AS WDGLJGDM,
			'渝中区卫计委' AS WDGLJGMC,
			F.KZRBM KZRGH,
			F.KZRXM KZRXM,
			F.ZRYSBM ZRYSBM,
			F.ZRYSXM ZRYSXM,
			F.ZZYSBM ZZYSBM,
			F.ZZYSXM ZZYSXM,
			F.ZYYSBM ZYYSBM,
			F.ZYYSXM ZYYSXM,
			F.ZRHSBM ZRHSBM,
			F.ZRHSXM ZRHSXM,
			F.JXYSBM JXYSBM,
			F.JXYSXM JXYSXM,
			F.SXYSBM SXYSBM,
			F.SXYSXM SXYSXM,
			F.BMYBM BMYBM,
			F.BMYXM BMYXM,
			F.YLXRGX YLXRGX,
			F.LXRDZMPH LXRDZMPH,
			F.LXRDZCMC  LXRDZCMC,
			F.LXRDZXMC LXRDZXMC,
			F.LXRDZQXMC LXRDZQXMC,
			F.LXRDZSMC LXRDZSMC,
			F.LXRDZSSMC LXRDZSSMC,
			NULL LXRDZYB,
			F.LXRXXDZ LXRXXDZ,
			F.LXRDZDHHM LXRDZDHHM,
			F.LXRXM LXRXM,
			A.RYTJ RYTJ,
			convert(datetime,STUFF(STUFF(STUFF(A.RYRQ ,5,0,'-'),8,0,'-'),11,0,' '), 20) RYSJ,
			convert(datetime,STUFF(STUFF(STUFF(A.CYRQ ,5,0,'-'),8,0,'-'),11,0,' '), 20) CYSJ,
			NULL BFHBS,
			F.RYKBBFMC RYKBBFMC,
			F.RYKBDM RYKBDM,
			F.RYKBMC RYKBMC,
			A.XSERYTZ XSERYTZ,
			A.XSECSTZ XSECSTZ,
			A.MJZZDMC JBZDMC,
			A.MZZDBM JBZDDM,
			A.BLZDMC BLZDMC,
			A.BLZD BLZDBM,
			NULL JBZTDM,
			A.SSWYMC SSZDYY,
			A.SSZD SSZDBM,
			A.HMDAY1 RYQT,
			A.HMHOUR1 RYQXS,
			A.HMMIN1 RYQF,
			A.HMDAY2 RYHT,
			A.HMHOUR2 RYHXS,
			A.HMMIN2 RYHF,
			F.ZKKBMC ZKKBMC,
			F.ZKKBDM ZKKBDM,
			NULL CYZYQZRQ,
			NULL CYZYZDMC,
			NULL CYZYJBZDDM,
			A.RYBQDM RYZYJBZDDM,
			NULL CYQTQZRQ,
			NULL CYQTZDMC,
			NULL CYQTJBZDDM,
			NULL RYQTJBZDDM,
			A.LYFS LYFS,
			A.JSYLJG1 LYYYMC,
			A.GMYW GMYW,
			A.XXDM ABOXXDM,
			A.RHJY RHXXDM,
			D.SSDM SSDM,
			convert(datetime,STUFF(STUFF(STUFF(D.SSRQ ,5,0,'-'),8,0,'-'),11,0,' '), 20) SSRQ,	
			NULL SSYSGH,
			D.SSYS SSYSXM,
			NULL SSYSZ1GH,
			D.SSYZ SSYSZ1XM,
			NULL SSYSZ2GH,
			D.SSEZ SSYSZ2XM,
			D.SSMC SSCZMC,	
			D.SSJB SSJB,
			D.SSQKLBDM SSQKLBDM,
			D.YHLB QKYHDJ,
			NULL MZYSGH,
			D.MZYS MZYSXM,
			A.RYCS ZYCS,
			A.ZYTS SJZYTS,
			NULL CYBFDM,
			F.CYKBBFMC CYKBBFMC,
			F.CYKBDM CYKBDM,
			F.CYKBMC CYKBMC,
			A.BARQ ZKRQ,
			F.ZKYSBM ZKYSBM,
			F.ZKYSXM ZKYSXM,
			F.ZKHSBM ZKHSBM,
			F.ZKHSXM ZKHSXM,
			A.ZZYMD CYZZYJHMD,
			A.BRXZ YLFKFSDM,
			A.ZFY ZFY,
			A.ZFJE ZFJE,
			A.YBYLFWF YLFWF,
			A.YBZLCZF ZLCZF,
			A.HLF HLF,
			A.QTF1 ZHYLQTFY,
			A.BLZDF BLZDF,
			A.SYSZDF SYSZDF,
			A.YXXZDF YXXZDF,
			A.LCZDXMF LCZDXMF,
			A.FSSZLXMF FSSZLXMF,
			A.LCWLZLF WLZLF,
			A.SSZLF SSZLF,
			A.MZF SSMZF,
			A.SSZLF SSF,
			A.KFF KFF,
			A.ZYZLF ZYZLF,
			A.XYF XYF,
			A.KJYWF KJYWF,
			A.CHENGYF ZCHYF,
			A.CAOYF ZCYF,
			A.SXF XF,
			A.BDBLZPF BDBLZPF,
			A.QDBLZPF QDBLZPF,
			A.NXYZLZPF NXYZLZPF,
			A.XBYZLZPF XBYZLZPF,
			A.JCYYCXCLF JCYYCLF,
			A.ZLYYCXCLF ZLYYCLF,
			A.SSYYCXCLF SSYYCLF,
			A.QTF2 QTF,
			A.MJ MJ,
			A.TBRQ TBRQ,
			'0' AS SCZT,
			0 AS CS_JYBZ,
			GETDATE() AS SCSJ
		FROM BA_SYJBK A(NOLOCK)
		LEFT JOIN ZYJZJLB B ON A.YLJGDM=B.YLJGDM and A.JZLSH=B.JZLSH
		LEFT JOIN SYS_ZCJG_DZ C(NOLOCK) ON A.YLJGDM=C.QPTDM
		LEFT JOIN BA_SYSSK D ON A.YLJGDM=D.YLJGDM and A.JZLSH=D.JZLSH
		LEFT JOIN ZY_BASY_FYXX E ON A.YLJGDM=E.YLJGDM and A.JZLSH=E.JZLSH
		LEFT JOIN ZY_BASY_PGBG F ON A.YLJGDM=F.YLJGDM and A.JZLSH=F.JZLSH
		WHERE a.TBRQ>ISNULL(@kssj,'1900-01-01') 
		and 
		(select top 1 JBXX.GRJBXXBSH from GXBZ_DA_GR_JBXX JBXX where JBXX.zjhm = A.SFZH) is not NULL
		--删除中间库中重复数据
		DELETE A FROM GXBZ_EMR_ZYBASY A,#TEMP_GXBZ_EMR_ZYBASY B
		WHERE A.GRJBXXBSH=B.GRJBXXBSH AND A.YLJG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_EMR_ZYBASY' 
			
		END TRY BEGIN CATCH
			SELECT 'F' AS SRESULT, '表：GXBZ_EMR_ZYBASY数据抽取失败！' AS SHINT, ERROR_MESSAGE() AS MSG
			ROLLBACK TRAN
			
		/*记录每步执行的记录日志*/
		INSERT INTO SYS_SCSJ_LOG(CONTENT,TABLENAME,RECORDTIME,RST,PROCNAME,MSG,ERRORCODE) 
		VALUES('表：GXBZ_EMR_ZYBASY数据抽取失败','GXBZ_EMR_ZYBASY',GETDATE(),'F','USP_GXBZ_EMR_ZYBASY',ERROR_MESSAGE(),ERROR_NUMBER())
	END CATCH
	END
END